package model

import (
	"database/sql"
	"time"

	"github.com/guregu/null"
	"github.com/satori/go.uuid"
)

var (
	_ = time.Second
	_ = sql.LevelDefault
	_ = null.Bool{}
	_ = uuid.UUID{}
)

/*
DB Table Details
-------------------------------------


CREATE TABLE "tracks"
(
    [TrackId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [Name] NVARCHAR(200)  NOT NULL,
    [AlbumId] INTEGER,
    [MediaTypeId] INTEGER  NOT NULL,
    [GenreId] INTEGER,
    [Composer] NVARCHAR(220),
    [Milliseconds] INTEGER  NOT NULL,
    [Bytes] INTEGER,
    [UnitPrice] NUMERIC(10,2)  NOT NULL,
    FOREIGN KEY ([AlbumId]) REFERENCES "albums" ([AlbumId])
		ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY ([GenreId]) REFERENCES "genres" ([GenreId])
		ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY ([MediaTypeId]) REFERENCES "media_types" ([MediaTypeId])
		ON DELETE NO ACTION ON UPDATE NO ACTION
)

JSON Sample
-------------------------------------
{    "track_id": 85,    "album_id": 7,    "media_type_id": 18,    "genre_id": 74,    "composer": "fSwAeuRKZskaswUArsyIrpjNP",    "unit_price": 0.6829975693121579,    "name": "qYoWVlvaWfxjWVoqGxoNlboqW",    "milliseconds": 31,    "bytes": 4}



*/

// Tracks struct is a row record of the tracks table in the main database
type Tracks struct {
	//[ 0] TrackId                                        integer              null: false  primary: true   isArray: false  auto: true   col: integer         len: -1      default: []
	TrackID int32 `gorm:"primary_key;AUTO_INCREMENT;column:TrackId;type:integer;" json:"track_id"`
	//[ 1] Name                                           nvarchar(200)        null: false  primary: false  isArray: false  auto: false  col: nvarchar        len: 200     default: []
	Name string `gorm:"column:Name;type:nvarchar;size:200;" json:"name"`
	//[ 2] AlbumId                                        integer              null: true   primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	AlbumID sql.NullInt64 `gorm:"column:AlbumId;type:integer;" json:"album_id"`
	//[ 3] MediaTypeId                                    integer              null: false  primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	MediaTypeID int32 `gorm:"column:MediaTypeId;type:integer;" json:"media_type_id"`
	//[ 4] GenreId                                        integer              null: true   primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	GenreID sql.NullInt64 `gorm:"column:GenreId;type:integer;" json:"genre_id"`
	//[ 5] Composer                                       nvarchar(220)        null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 220     default: []
	Composer sql.NullString `gorm:"column:Composer;type:nvarchar;size:220;" json:"composer"`
	//[ 6] Milliseconds                                   integer              null: false  primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	Milliseconds int32 `gorm:"column:Milliseconds;type:integer;" json:"milliseconds"`
	//[ 7] Bytes                                          integer              null: true   primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	Bytes sql.NullInt64 `gorm:"column:Bytes;type:integer;" json:"bytes"`
	//[ 8] UnitPrice                                      numeric              null: false  primary: false  isArray: false  auto: false  col: numeric         len: -1      default: []
	UnitPrice float64 `gorm:"column:UnitPrice;type:numeric;" json:"unit_price"`
}

var tracksTableInfo = &TableInfo{
	Name: "tracks",
	Columns: []*ColumnInfo{

		{
			Index:              0,
			Name:               "TrackId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       true,
			IsAutoIncrement:    true,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "TrackID",
			GoFieldType:        "int32",
			JSONFieldName:      "track_id",
			ProtobufFieldName:  "track_id",
			ProtobufType:       "int32",
			ProtobufPos:        1,
		},

		{
			Index:              1,
			Name:               "Name",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(200)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       200,
			GoFieldName:        "Name",
			GoFieldType:        "string",
			JSONFieldName:      "name",
			ProtobufFieldName:  "name",
			ProtobufType:       "string",
			ProtobufPos:        2,
		},

		{
			Index:              2,
			Name:               "AlbumId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "AlbumID",
			GoFieldType:        "sql.NullInt64",
			JSONFieldName:      "album_id",
			ProtobufFieldName:  "album_id",
			ProtobufType:       "int32",
			ProtobufPos:        3,
		},

		{
			Index:              3,
			Name:               "MediaTypeId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "MediaTypeID",
			GoFieldType:        "int32",
			JSONFieldName:      "media_type_id",
			ProtobufFieldName:  "media_type_id",
			ProtobufType:       "int32",
			ProtobufPos:        4,
		},

		{
			Index:              4,
			Name:               "GenreId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "GenreID",
			GoFieldType:        "sql.NullInt64",
			JSONFieldName:      "genre_id",
			ProtobufFieldName:  "genre_id",
			ProtobufType:       "int32",
			ProtobufPos:        5,
		},

		{
			Index:              5,
			Name:               "Composer",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(220)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       220,
			GoFieldName:        "Composer",
			GoFieldType:        "sql.NullString",
			JSONFieldName:      "composer",
			ProtobufFieldName:  "composer",
			ProtobufType:       "string",
			ProtobufPos:        6,
		},

		{
			Index:              6,
			Name:               "Milliseconds",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "Milliseconds",
			GoFieldType:        "int32",
			JSONFieldName:      "milliseconds",
			ProtobufFieldName:  "milliseconds",
			ProtobufType:       "int32",
			ProtobufPos:        7,
		},

		{
			Index:              7,
			Name:               "Bytes",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "Bytes",
			GoFieldType:        "sql.NullInt64",
			JSONFieldName:      "bytes",
			ProtobufFieldName:  "bytes",
			ProtobufType:       "int32",
			ProtobufPos:        8,
		},

		{
			Index:              8,
			Name:               "UnitPrice",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "numeric",
			DatabaseTypePretty: "numeric",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "numeric",
			ColumnLength:       -1,
			GoFieldName:        "UnitPrice",
			GoFieldType:        "float64",
			JSONFieldName:      "unit_price",
			ProtobufFieldName:  "unit_price",
			ProtobufType:       "float",
			ProtobufPos:        9,
		},
	},
}

// TableName sets the insert table name for this struct type
func (t *Tracks) TableName() string {
	return "tracks"
}

// BeforeSave invoked before saving, return an error if field is not populated.
func (t *Tracks) BeforeSave() error {
	return nil
}

// Prepare invoked before saving, can be used to populate fields etc.
func (t *Tracks) Prepare() {
}

// Validate invoked before performing action, return an error if field is not populated.
func (t *Tracks) Validate(action Action) error {
	return nil
}

// TableInfo return table meta data
func (t *Tracks) TableInfo() *TableInfo {
	return tracksTableInfo
}
